package design.mode.effective_java.chapter5.item26;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * @author ZhongMingde on 2021/8/16
 */

public class Error {

    private final Collection<Stamp> stamps = null;

   /* public static void main(String[] args) {
          错误的使用
         Collection stamps = new ArrayList();
         stamps.add(new Coin());
        Stamp stamp = null;
        for (Iterator i = stamps.iterator(); i.hasNext(); )
            stamp = (Stamp) i.next(); // Throws ClassCastException
        stamp.cancel();
    }*/


    // 运行时失败- unsafeAdd方法使用原始类型(List)!
    public static void main(String[] args) {
        List<Object> strings = new ArrayList<>();
        unsafeAdd(strings, Integer.valueOf(42));
        String s = (String) strings.get(0);
    }

    private static void unsafeAdd(List list, Object o) {
        list.add(o);
    }

    static int numElementsInCommon(Set<?> s1,Set<?> s2){
        int result = 0;
        for (Object o1 : s1) {
            if (s2.contains(o1)){

            }

        }
        result ++;
        return result;
    }
}
